package yxy.game.pm2.module.wuchao.event;

import java.util.Collection;

import yxy.apple.util.RandomUtility;
import yxy.cherry.data.DataCenter;
import yxy.cherry.data.bean.wuchaogtopic;
import yxy.game.pm2.message.WuchaoMessage;

/** 乌巢事件 问答 */
public class WuchaoEventQuiz extends WuchaoEvent {
	@Override
	public EventType getEventType() {
		return EventType.Quiz;
	}

	@Override
	protected void _packageInfo(WuchaoMessage.WuchaoEvent.Builder builder) {
		builder.setQuiz(getDataId());
	}

	private int dataId;

	public void setDataId(int dataId) {
		this.dataId = dataId;
	}

	public int getDataId() {
		return dataId;
	}

	public static WuchaoEventQuiz create() {
		WuchaoEventQuiz event = new WuchaoEventQuiz();

		Collection<wuchaogtopic> all = DataCenter.getAllData(wuchaogtopic.class).values();
		int i = RandomUtility.nextInt(0, all.size());
		int n = 0;
		for (wuchaogtopic data : all) {
			if (n++ >= i) {
				event.setDataId(data.getId());
				break;
			}
		}

		return event;
	}

}
